package com.gdip.controller;

import com.gdip.common.dtos.ResponseResult;
import com.gdip.po.CommentPo;
import com.gdip.service.CommentService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: CommentController
 * Package: com.gdip.controller
 *
 * @Author 南浔
 * @Create 2024/4/11 23:08
 * @Version 1.0
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentService commentService;

    // 添加评论
    @PostMapping("/insert")
    public ResponseResult insert_comment(@RequestBody CommentPo commentPo) {
        return commentService.insert_comment(commentPo);
    }

    // 单一查询信息,根据问题id和用户id
    @GetMapping("/getComment")
    public ResponseResult getComment(@RequestParam int problemId, HttpSession session) {
        Integer userId = (Integer) session.getAttribute("userId");
        return commentService.getComment(userId, problemId);
    }

    // 整体满意度
    @GetMapping("/commentAll")
    public ResponseResult commentAll() {
        return commentService.commentAll();
    }

    // 按年份统计满意度
    @GetMapping("/commentYear")
    public ResponseResult commentYear() {
        return commentService.commentYear();
    }

    // 部门满意度排名
    @GetMapping("/comment_classRank")
    public ResponseResult comment_classRank() {
        return commentService.comment_classRank();
    }

    // 按部门统计满意度
    @GetMapping("/comment_class")
    public ResponseResult comment_class() {
        return commentService.comment_class();
    }

    // 查询所有评论，返回每条记录的创建时间和评分
    @GetMapping("/getCommentAll")
    public ResponseResult getCommentAll() {
        return commentService.getCommentAll();
    }

    // 按部门查询对应的所有评论，返回每条记录的创建时间和评分
    @GetMapping("/getCommentByClass")
    public ResponseResult getCommentByClass(@RequestParam int classId) {
        return commentService.getCommentByClass(classId);
    }
}
